package com.lgc.javathread.joinTest.test2;

public class JoinThread extends Thread {
    JoinThread joinThread;
    public JoinThread(String name,JoinThread joinThread) {
        super(name);
        this.joinThread=joinThread;
    }

    @Override
    public void run() {
        for (int i=0;i<100;i++){
            System.out.println(this.getName()+"----i"+i);

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if(i==3 && this.getName().equals("小军")) {
                try {
                    joinThread.join(); //使当线程进入等待池并等待joinThread线程执行完毕后才会被唤醒
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
